#pragma once

#include <windows.h>
#include <xnamath.h>
#include <vector>
#include <map>

struct KeyFrame
{
	float TimePos;
	XMFLOAT3 Translation;
	XMFLOAT3 Scale;
	XMFLOAT4 RotationQuat;
};

struct BoneAnimation
{
	float GetStartTime()const;
	float GetEndTime()const;

	void Interpolate(float t, XMFLOAT4X4& M)const;
	std::vector<KeyFrame> Keyframes;
};

//an animationclip requires a BoneAnimation for every bone to form the animationclip
struct AnimationClip
{
	//smallest start time over all bones in this clip
	float GetClipStartTime() const;
	//largest end time over all bones in this clip
	float GetClipEndTime() const;
	//loops over each BoneAnimation in the clip and interpolates the animation
	void Interpolate(float t, std::vector<XMFLOAT4X4>& boneTransforms) const;
	//Animation for each bone
	std::vector<BoneAnimation> BoneAnimations;

};

class SkinnedData
{
public:
	UINT BoneCount() const;
	float  GetClipStartTime(const std::string& clipName) const;
	float GetClipEndTime(const std::string & clipName)const;
	void Set(std::vector<int>& boneHierachy, std::vector<XMFLOAT4X4>& boneOffsets,
		std::map<std::string, AnimationClip>& animations);
	void GetFinalTransforms(const std::string& clipName, float timePos, std::vector<XMFLOAT4X4>& finalTransforms) const;

	std::map<std::string, AnimationClip> mAnimations;
private:
	//gives parentindex of ith bone. the ith bone corresponds to the ith BoneAnimation in an animationclip
	std::vector<int> mBoneHierachy;
	//offset transform of ith bone
	std::vector<XMFLOAT4X4> mBoneOffsets;
};

